﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Sherwood.Localization;
using Sherwood.Localization.Resx;


namespace Sherwood.Localization.Tests
{
    [TestClass]
    public class ResxProviderTests
    {

        
        /// <summary>
        /// Test ResxTranslation provider using a non-supported culture.
        /// </summary>
        [TestMethod]
        public void TranslationTest_Dutch() 
        {
            //Arrange
            ITranslationProvider provider = new ResxTranslationProvider(typeof(Sherwood.Localization.Tests.TestResources),"nl");

            //Act
            string neutralString = provider["neutralstring"];
            string enusstring = provider["enusstring"];
            string enstring = provider["enstring"];
            string enstringwithdefault = provider.GetString("enstring", "--not found--");

            //Assert
            Assert.AreEqual<string>("String", neutralString); //found
            Assert.AreEqual<string>("enusstring", enusstring); //not found, defaults to key
            Assert.AreEqual<string>("enstring", enstring); //not found, defaults to key
            Assert.AreEqual<string>("--not found--", enstringwithdefault); //not found, defaults to specified default
        }

        /// <summary>
        /// Test ResxTranslationProvider using a supported culture.
        /// Test switching cultures.
        /// </summary>
        [TestMethod]
        public void TranslationTest_EnglishUS() //country specific culture
        {
            //Arrange
            ITranslationProvider provider = new ResxTranslationProvider(typeof(Sherwood.Localization.Tests.TestResources), "en-US");

            //Act
            string neutralString = provider["neutralstring"];
            string enusstring = provider["enusstring"];
            string bogusstring = provider["bogus"];
            string boguswithdefault = provider.GetString("bogus", "--not found--");
            provider.SetCulture("de-DE"); //switch language
            string neutralString2 = provider["neutralstring"];

            //Assert
            Assert.AreEqual<string>("String (English)", neutralString); //found in .en resource file
            Assert.AreEqual<string>("English (US)", enusstring); //found in .en-us resource file
            Assert.AreEqual<string>("bogus", bogusstring); //not found, defaults to key
            Assert.AreEqual<string>("--not found--", boguswithdefault); //not found, defaults to specified default
            Assert.AreEqual<string>("String", neutralString2); //neutral string should now be less specific (taken from default resx)
        }
    }

   
}
